var urlsupply = host+"supply/getdata/"+type_supp;
var colsupply = [];
var componen_supply = 'supply_'+type_supp;

colsupply[0] = new Array();

if(type_supp == "pesanan_konsumen"){	
	colsupply[0][0] = {title:'Pesanan Barang', colspan: 3,};
	colsupply[1] 	  = new Array();				
	colsupply[1][0] =   {field:'no_surat_pesanan',title:'No. Pesanan Surat',width:200,halign:'center'};
}

$("#"+type_supp).datagrid({
    title:'',
    height:frmHeight-317,
    width:frmWidth-280,
	iconCls: 'table',
	rownumbers:true,
    fit:false,
    striped:false,
    pagination:true,
    sortable:true,
    url:urlsupply,		
	nowrap: true,
    singleSelect:true,
	pagination:true,
	onLoadSuccess: function(data){
		if(data.total == 0){
			var $panel = $(this).datagrid('getPanel');
			var $info = '<div class="info-empty">Tidak Ada Data</div>';
			$($panel).find(".datagrid-view2 .datagrid-body").append($info);
			//$('#edit_data').linkbutton({disabled:true});
			//$('#delete_data').linkbutton({disabled:true});
		}
	},		
	//toolbar:'#toolbar_'+type_supp,	
    columns:colsupply,
});

var tinggiregionsupply = frmHeight-248;

function addsupply(){
	$('#'+componen_supply).html('');
	$('#'+componen_supply).addClass("loading");
	$.post('supply/getform/add/'+type_supp,{'tinggiregion':tinggiregionsupply},function(resp){
		$('#'+componen_supply).removeClass('loading')
		$('#'+componen_supply).html(resp);
	});
}

function editsupply(){
	var datasupply = $("#"+type_supp).datagrid('getSelected');

	if(datasupply){
		$('#'+componen_supply).html('');
		$('#'+componen_supply).addClass("loading");
		$.post('supply/getform/edit/'+type_supp, {'tinggiregion':tinggiregionsupply, 'id':datasupply.id}, function(resp){
			$('#'+componen_supply).removeClass('loading')
			$('#'+componen_supply).html(resp);
		});
	}else{
		$.messager.alert('warning','Pilih Data Yang Akan Diedit!!','Peringatan');
	}
}

function cari_data(mod){
	switch(mod){
		case 'pesanan_konsumen':
			if($("#category_"+type_supp).val() == 'C.nama_barang'){
				val_nya = $('#barang_pesanan').val();
			}
			
			if($("#category_"+type_supp).val() == 'C.nama_barang'){
				$("#"+type_supp).datagrid('reload',{field:$("#category_"+type_supp).val(), val:val_nya});		
			}
		break;
	}
}

